package my.edu.model.commodity.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotBlank;
import my.edu.common.validate.groups.Insert;
import my.edu.common.domain.Response;
import my.edu.model.commodity.entity.dto.PricingSchemeDTO;
import my.edu.model.commodity.service.IPricingSchemeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/commodity/pricingScheme")
@RestController
@Tag(name = "价格调整方案接口")
@Validated//接口单一参数校验必须添加此注解
public class PricingSchemeController {
    @Autowired
    private IPricingSchemeService pricingSchemeService;

    @PutMapping
    @RequiresPermissions("price:save")
    @Operation(summary = "新增价格调整方案")
    public Response save(@Validated(value = Insert.class) @RequestBody PricingSchemeDTO pricingSchemeDTO) {
        pricingSchemeService.savenew(pricingSchemeDTO);
        return Response.success();
    }

    @GetMapping
    @RequiresPermissions("price:get")
    @Operation(summary = "获取价格调整方案列表")
    public Response getAccount() {
        return Response.success(pricingSchemeService.listAll());
    }

    @GetMapping("/{id}")
    @RequiresPermissions("price:get")
    @Operation(summary = "根据编号获取价格调整方案信息")
    public Response getVOById(@PathVariable @NotBlank(message = "id不能为空") Long id) {
        return Response.success(pricingSchemeService.getVoById(id));
    }

    @PostMapping("/update")
    @RequiresPermissions("price:update")
    @Operation(summary = "更新价格调整方案信息")
    public Response update(@Validated @RequestBody  PricingSchemeDTO pricingSchemeDTO) {
        pricingSchemeService.updateByDTO(pricingSchemeDTO);
        return Response.success();
    }
}
